#include "SipSubscription.hpp"
#include "SipDialogSet.hpp"
#include "SipUserAgent.hpp"


namespace wtsip{


CSipSubscription::CSipSubscription(CSipDialogSet& dlgset, const resip::Uri& local, const resip::Uri& remote):
CSipDialogBase(dlgset, local, remote){
    m_DlgType = Subscription;
}


CSipSubscription::CSipSubscription(CSipDialogSet& dlgset, SipMessage& msg):
CSipDialogBase(dlgset, msg){
    m_DlgType = Subscription;
}


CSipSubscription::~CSipSubscription(){}


//bool CSipSubscription::onRequest(CSipClnTransaction& clntran, SipMessage& msg){
//    return true;
//}


bool CSipSubscription::onResponse(CSipClnTransaction& clntran, SipMessage& msg){
    return true;
}


bool CSipSubscription::onRequest(CSipSrvTransaction& srvtran, SipMessage& msg){
    return true;
}


//bool CSipSubscription::onResponse(CSipSrvTransaction& srvtran, SipMessage& msg){
//    return true;
//}


SipMessage* CSipSubscription::createSubscribe()
{
    CSipUserAgent& ua = m_dlgset.getUserAgent();
    SipMessage* msg = ua.createSubscribeMsg(m_RemoteNameAddr, m_LocalNameAddr);
    msg->header(h_CallId).value() = m_CallId;
    msg->header(h_From).param(p_tag) = m_LocalNameAddr.param(p_tag);
    if (m_RemoteNameAddr.exists(p_tag)){
        msg->header(h_To).param(p_tag) = m_RemoteNameAddr.param(p_tag);
    }
    msg->header(h_CSeq).sequence() = ++m_fwCSeq;

    return msg;
}


SipMessage* CSipSubscription::createNotify()
{
    CSipUserAgent& ua = m_dlgset.getUserAgent();
    SipMessage* msg = ua.createRequest(m_RemoteNameAddr, m_LocalNameAddr, resip::NOTIFY);
    msg->header(h_CallId).value() = m_CallId;
    msg->header(h_From).param(p_tag) = m_LocalNameAddr.param(p_tag);
    if (m_RemoteNameAddr.exists(p_tag)){
        msg->header(h_To).param(p_tag) = m_RemoteNameAddr.param(p_tag);
    }
    msg->header(h_CSeq).sequence() = ++m_fwCSeq;

    return msg;
}



}//namespace

